<template>
  <div class="main-scroll">
    <headerc :title="title"></headerc>
    <el-card class="box-card">
      <div style="padding: 10px" class="c-filter">
        <el-form
          :inline="true"
          :model="filterForm"
          class="demo-form-inline"
          label-width="70px"
        >
          <el-form-item label="输入查询">
            <el-input
              v-model="filterForm.empName"
              placeholder="员工姓名"
            ></el-input>
          </el-form-item>

          <el-form-item label="部门">
            <el-input v-model="filterForm.dept" placeholder="请填写"></el-input>
          </el-form-item>

          <el-form-item label="二级部门">
            <el-input
              v-model="filterForm.workshop"
              placeholder="请填写"
            ></el-input>
          </el-form-item>

          <el-form-item label="班组">
            <el-input v-model="filterForm.team" placeholder="请填写"></el-input>
          </el-form-item>

          <el-form-item label="日期">
            <el-date-picker
              v-model="filterForm.scoreTime"
              type="date"
              placeholder="变更时间"
              value-format="yyyy-MM-dd"
              @change="changeDate"
            >
            </el-date-picker>
          </el-form-item>
          <el-row>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="query"
                >查询</el-button
              >
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="reset">清除查询条件</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </div>
    </el-card>
    <el-card>
      <!-- <div class="main-seting">
        <div> -->
      <!-- <div class="title-text">数据列表</div> -->
      <el-button
       v-auth="'C08001'"
        style="
          float: right;
          margin-right: 20px;
          margin-bottom: 20px;
          margin-top: 20px;
        "
        icon="el-icon-download"
        @click="exportExcel"
        >导出</el-button
      >
      <div style="margin: 20px; min-height: 55vh">
        <el-table
          :data="backgroundList"
          border
          style="width: 100%"
          :header-cell-style="{ background: '#F6F7FB' }"
        >
          <el-table-column
            type="index"
            :index="indexAdd"
            label="序号"
            width="50"
          >
          </el-table-column>
          <el-table-column label="部门">
            <template slot-scope="scope">
              <p>{{ scope.row.dept }}</p>
            </template>
          </el-table-column>
          <el-table-column label="二级部门">
            <template slot-scope="scope">
              <p>{{ scope.row.workshop }}</p>
            </template>
          </el-table-column>
          <el-table-column label="班组">
            <template slot-scope="scope">
              <p>{{ scope.row.team }}</p>
            </template>
          </el-table-column>
          <el-table-column label="姓名">
            <template slot-scope="scope">
              <p>{{ scope.row.empName }}</p>
            </template>
          </el-table-column>
          <el-table-column label="年份">
            <template slot-scope="scope">
              <p>{{ scope.row.year }}</p>
            </template>
          </el-table-column>
          <el-table-column label="月份">
            <template slot-scope="scope">
              <p>{{ scope.row.month }}</p>
            </template>
          </el-table-column>
          <el-table-column label="培训">
            <template slot-scope="scope">
              <p>{{ scope.row.trainingScore }}</p>
            </template>
          </el-table-column>
          <el-table-column label="安全活动">
            <template slot-scope="scope">
              <p>{{ scope.row.activityScore }}</p>
            </template>
          </el-table-column>
          <el-table-column label="创新建议">
            <template slot-scope="scope">
              <p>{{ scope.row.suggestScore }}</p>
            </template>
          </el-table-column>
          <el-table-column label="反三违">
            <template slot-scope="scope">
              <p>{{ scope.row.accidentScore }}</p>
            </template>
          </el-table-column>
          <el-table-column label="合计">
            <template slot-scope="scope">
              <p>{{ scope.row.score }}</p>
            </template>
          </el-table-column>
          <el-table-column label="备注" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <p>{{ scope.row.remark }}</p>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        v-if="isUpdate"
        background
        layout="prev, pager, next"
        :page-size="pageSize"
        :total="total"
        :hide-on-single-page="total < 10"
        @current-change="currentChange"
        style="margin-left: 25%"
      >
      </el-pagination>
      <!-- </div>
      </div> -->
    </el-card>
  </div>
</template>

<script>
import headerc from '@/components/header.vue'
import { exportMethod } from '@/utils/utils'
import { getBackground } from '@/api/personal-files'
export default {
  components: {
    headerc
  },
  data() {
    return {
      isUpdate: true,
      title: '个人积分统计表',
      form: '',
      value1: '',
      filterForm: {
        empName: '',
        dept: '',
        workshop: '',
        team: '',
        scoreTime: ''
      },
      pageNo: 1, // 分页页码
      pageSize: 10, // 每页条数
      total: 0,
      backgroundList: [],
      dialogVisible: false
    }
  },
  created() {
    this.getBackgroundList()
  },
  methods: {
    exportExcel() {
      const data = {
        dept: this.filterForm.dept,
        empName: this.filterForm.empName,
        pageNo: this.pageNo,
        pageSize: 5000,
        scoreTime: this.filterForm.scoreTime,
        team: this.filterForm.team,
        workshop: this.filterForm.workshop
      }
      exportMethod('score', data, '个人积分统计表')
    },
    // 序号-页面切换递增
    indexAdd(index) {
      return index + 1 + (this.pageNo - 1) * this.pageSize
    },
    changeDate(date) {
      this.filterForm.scoreTime = date
    },
    currentChange(pageNo) {
      this.pageNo = pageNo
      this.getBackgroundList()
    },
    async getBackgroundList() {
      const res = await getBackground({
        // dateRange: [],
        dept: this.filterForm.dept,
        empName: this.filterForm.empName,
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        scoreTime: this.filterForm.scoreTime,
        team: this.filterForm.team,
        workshop: this.filterForm.workshop
      })
      if (res.code == 200) {
        this.backgroundList = res.data.list
        this.total = res.data.total
        this.isUpdate = true
      }
    },
    query() {
      this.pageNo = 1
      this.isUpdate = false
      this.getBackgroundList()
    },
    onSubmit() {
      console.log('submit!')
    },
    reset() {
      this.filterForm.empName = ''
      this.filterForm.dept = ''
      this.filterForm.workshop = ''
      this.filterForm.team = ''
      this.filterForm.scoreTime = ''
    }
  }
}
</script>

<style lang="scss" scoped>
.c-main-make {
  margin-left: 35px;
  height: 300px;
  background: #fff;
  margin-right: 35px;
  margin-bottom: 35px;
  position: relative;
  overflow: hidden;
  border: 1px #dcdee0 solid;
}
.c-main-show {
  margin-left: 35px;
  min-height: 700px;
  background: #fff;
  margin-right: 35px;
  margin-bottom: 35px;
  position: relative;
  overflow: hidden;
  border: 1px #dcdee0 solid;
}
.title-text {
  width: 100%;
  height: 50px;
  border-bottom: 1px #dcdee0 solid;
  font-family: '微软雅黑 Bold', '微软雅黑 Regular', 微软雅黑, sans-serif;
  font-weight: 700;
  color: #666666;
  line-height: 50px;
  padding-left: 25px;
}

.main-scroll {
  height: 1000px;
  // overflow-y: scroll;
}
.pagination {
  display: flex;
  justify-content: end;
}
.box-card {
  margin-bottom: 20px;
}
.el-input {
  width: 250px;
}
.el-select {
  width: 250px;
}
</style>
